<%@ page import="sixyz.entity.Book" %>
<%@ page import="sixyz.dao.BookDAO" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="sixyz.service.BookService" %><%--
  Created by IntelliJ IDEA.
  User: Starry:123xsz
  Date: 2022/4/11
  Time: 22:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>index</title>
  <link rel="stylesheet" type="text/css" href="css/index.css"/>
</head>
<body>
<div id="top">
  <h1>图一份神闲气静, 书几笔悦目赏心</h1>
</div>
<div id="right">
  <h2>您已登录，${user.nickname}</h2>
  <%
    BookService bookService = new BookService();
    ArrayList<Book> bookData = bookService.listAllBooks();
  %>
  <table border="1">
    <tr>
      <th>Id</th>
      <th>Name</th>
      <th>Author</th>
      <th>Description</th>
      <th>Delete</th>
    </tr>
    <%
      for (Book bookDatum : bookData) {
    %>
    <tr>
      <td><%= bookDatum.getId()%></td>
      <td><%= bookDatum.getName()%></td>
      <td><%= bookDatum.getAuthor()%></td>
      <td><%= bookDatum.getDescription()%></td>
      <td><a href="deleteBook?id=<%=bookDatum.getId() %>">点此删除</a></td>
    </tr>
    <%  } %>
  </table>
<%--  <h2>-----------------------------------------------------------------------------------------------------------------</h2>--%>
  <h2>Add new</h2>
  <form action="addBook" method="post">
    <label>
      <input type="text" name="name" placeholder="book name"
             required oninvalid="setCustomValidity('Book name is required')"
             oninput="setCustomValidity('')">
    </label> <br>
    <label>
      <input type="text" name="author" placeholder="author"
             required oninvalid="setCustomValidity('Book author is required')"
             oninput="setCustomValidity('')">
    </label> <br>
    <label>
      <input type="text" name="description" placeholder="description"
             required oninvalid="setCustomValidity('Please enter brief description')"
             oninput="setCustomValidity('')">
    </label> <br>
    <button class="but" type="submit">add now</button>
  </form>
</div>
</body>
</html>
